import { sentryVitePlugin } from "@sentry/vite-plugin";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import WindiCSS from "vite-plugin-windicss";

// https://vitejs.dev/config/
export default defineConfig({
  base: "/",
  plugins: [
    react({
      jsxImportSource: "@dbfu/react-directive",
    }),
    WindiCSS(),
    sentryVitePlugin({
      org: "dbfu-e3b959e09",
      project: "javascript-react",
      authToken: process.env.SENTRY_AUTH_TOKEN,
      sourcemaps: {
        filesToDeleteAfterUpload: ["dist/**/*.js.map"], // 上传后删除 sourcemap 文件
      },
    }),
  ],
  resolve: {
    alias: {
      "@": "/src/",
    },
  },
  build: {
    manifest: true,
    sourcemap: true,
  },
  server: {
    proxy: {
      "/api": {
        target: "http://localhost:7001",
        changeOrigin: true,
      },
      "/file": {
        target: "http://localhost:9002",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/file/, ""),
      },
      "/ws": {
        target: "ws://localhost:7001",
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(/^\/ws/, ""),
      },
    },
  },
});
